package cn.psvmc.cxzapi.controller.market;

import cn.psvmc.cxzapi.model.common.DelEntity;
import cn.psvmc.cxzapi.model.common.MarketEntity;
import cn.psvmc.cxzapi.model.market.TBanner2;
import cn.psvmc.cxzapi.response.Result;
import cn.psvmc.cxzapi.response.ResultGenerator;
import cn.psvmc.cxzapi.service.market.TBanner2Service;
import cn.psvmc.cxzapi.util.ToolUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 1+2Banner 实例管理
 * @Author auto
 * @Date 2024-08-13
 */
@RestController
@RequestMapping("/banner2")
public class TBanner2Controller {

    @Resource
    private TBanner2Service tBanner2Service;

    /**
    * @Author auto 2024-08-13 新增1+2Banner 实例表
    * @Param tBanner2 1+2Banner 实例表
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/add")
    public Result add(@RequestBody TBanner2 tBanner2) {
        ToolUtils.validation(new Object[]{
                tBanner2.getComponentId(), "组件id", 2
                , tBanner2.getBannerPosition(), "位置", 1
                , tBanner2.getSortType(), "分类类型", 1
                , tBanner2.getIdAddress(), "对应ID或地址", 2
        });
        tBanner2Service.add(tBanner2);
        return ResultGenerator.genSuccessResult("保存成功！");
    }

    /**
    * @Author auto 2024-08-13 更新1+2Banner 实例表
    * @Param tBanner2 1+2Banner 实例表模型
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/edit")
    public Result edit(@RequestBody TBanner2 tBanner2) {
        ToolUtils.validation(new Object[]{tBanner2.getBannerId(), "id", 1, tBanner2.getRversion(), "版本", 1});
        tBanner2Service.edit(tBanner2);
        return ResultGenerator.genSuccessResult("更新成功！");
    }

    /**
    * @Author auto 2024-08-13 删除1+2Banner 实例表
    * @Param [entity] 删除实体类
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/delete")
    public Result delete(@RequestBody DelEntity entity) {
        Integer id = entity.getId();
        Integer rversion = entity.getRversion();
        ToolUtils.validation(new Object[]{id, "id", 1, rversion, "版本", 1});
        int delResult = tBanner2Service.delete(id, rversion);
        if (delResult > 0) {
            return ResultGenerator.genSuccessResult("删除成功！");
        }
        return ResultGenerator.genFailResult("删除失败！");
    }

    /**
     * @Description 列表
     * @Date 2024/8/13 17:06
     * @Author YWX
     * @Param []
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list")
    public Result list(@RequestBody MarketEntity entity) {
        ToolUtils.validation(new Object[]{entity.getComponentId(), "组件id", 2});
        return ResultGenerator.genSuccessResult("查询成功！", tBanner2Service.listAll(entity));
    }
}
